package com.hoyue.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {

	 public static String EncoderByMd5(String password){
		 try {
			 // 得到一个信息摘要器
			 MessageDigest digest = MessageDigest.getInstance("md5");
			 byte[] result = digest.digest(password.getBytes());
			 StringBuffer buffer = new StringBuffer();
			 for (byte b : result) {
				 int number = b & 0xf6;// 加盐
				 String str = Integer.toHexString(number);
				 if (str.length() == 1) {
					 buffer.append("0");
				 }
				 buffer.append(str);
			 }
			 return buffer.toString();
		 } catch (NoSuchAlgorithmException e) {
			 e.printStackTrace();
			 return "";
		 }
	 }
}
